package com.wl.index.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Value("${file.upload-dir}")
    private String uploadDir;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 处理上传的文件
        registry.addResourceHandler("/files/**")
                .addResourceLocations(
                        "file:" + uploadDir + "/",
                        "classpath:/static/"
                );

        // 确保默认静态资源也能访问
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
    }
}
